import ObjManager = require('./../kernel/cont/ObjManager');
import GroupObj = require('./../kernel/obj/GroupObj');
import SJGReplaceGroup = require('./../kernel/replace/SJGReplaceGroup');
import SJGReplaceGroupAdvance = require('./../kernel/replace/SJGReplaceGroupAdvance');
import ObjPositionAlign = require('./../kernel/base/ObjPositionAlign');
import ObjPosition = require('./../kernel/base/ObjPosition');
import Point = require('./../common/graph/Point');
export =SJGTypeSetBoxUtil2;

class SJGTypeSetBoxUtil2 {
    public static MAX_BOX_NUM: number=8; // 可替换数组中最多有8个元素
    
    public static kindWs: Object={}; // 某种kind的不同个数下的宽度数组，如 kind-[W1,W2,W3,W4,W5,W6,W7,W8]
    public static kindHs: Object={}; // 某种kind的不同个数下的高度数组，如 kind-[W1,W2,W3,W4,W5,W6,W7,W8]
    
    // 从m个子增减到n个子，引起的宽高比例变化
    // 参数：m 原个数,范围[1,MAX_BOX_NUM]  
    // 参数：n 新个数,范围[1,MAX_BOX_NUM]
    // 参数：extend_method  扩展方式
    // 参数：limit  当扩展方式为水平扩展时表示一行的最大个数，当扩展方式为垂直扩展时表示一列的最大个数
    // 返回：数组，2个元素：宽的变化比例，高的变化比例
    // 注意：使用此接口之前，必须调用calcKindWHs初始化kindWs和kindHs
    public static calcRatioXY(m: number,n: number,extend_method: number,limit: number): Array<number> {
        var ws: Array<number>=SJGTypeSetBoxUtil2.kindWs[extend_method];
        var hs: Array<number>=SJGTypeSetBoxUtil2.kindHs[extend_method];
        
        
        // 水平扩展／垂直扩展需要考虑limit
        var newW: number=ws[n-1],oldW=ws[m-1],
            newH=hs[n-1],oldH=hs[m-1];
        if(extend_method==SJGReplaceGroup.HORIZON) {
            var groupW: number=100;
            var groupH: number=100;

            var oldRows: number=Math.floor((m-1)/limit)+1;
            var oldCols: number=Math.floor((m-1)%limit)+1;
            if(oldRows>1) {
                oldCols=limit;
            }
            oldW=groupW/oldCols;
            oldH=groupH/oldRows;

            var newRows: number=Math.floor((n-1)/limit)+1;
            var newCols: number=Math.floor((n-1)%limit)+1;
            if(newRows>1) {
                newCols=limit;
            }
            newW=groupW/newCols;
            newH=groupH/newRows;

        } else if(extend_method==SJGReplaceGroup.VERTICLE) {
            var groupW: number=100;
            var groupH: number=100;

            var oldCols: number=Math.floor((m-1)/limit)+1;
            var oldRows: number=Math.floor((m-1)%limit)+1;
            if(oldCols>1) {
                oldRows=limit;
            }
            oldW=groupW/oldCols;
            oldH=groupH/oldRows;

            var newCols: number=Math.floor((n-1)/limit)+1;
            var newRows: number=Math.floor((n-1)%limit)+1;
            if(newCols>1) {
                newRows=limit;
            }
            newW=groupW/newCols;
            newH=groupH/newRows;
        }


        return [newW/oldW,newH/oldH];
    }
    
    // 计算所有kind的不同个数下的宽高度数组
    public static calcKindWHs() {
        SJGTypeSetBoxUtil2.calcOneKindWHS(SJGReplaceGroup.HORIZON);
        SJGTypeSetBoxUtil2.calcOneKindWHS(SJGReplaceGroup.VERTICLE);
        SJGTypeSetBoxUtil2.calcOneKindWHS(SJGReplaceGroup.CIRCLE);
        SJGTypeSetBoxUtil2.calcOneKindWHS(SJGReplaceGroup.RECT);
        SJGTypeSetBoxUtil2.calcOneKindWHS(SJGReplaceGroup.W);
        SJGTypeSetBoxUtil2.calcOneKindWHS(SJGReplaceGroup.PATH);
    }
    // 计算某种kind的不同个数下的宽高度数组
    // 参数：extend_method  扩展方式
    private static calcOneKindWHS(extend_method: number) {
        var groupW: number=100;
        var groupH: number=100;
        var advance: SJGReplaceGroupAdvance=new SJGReplaceGroupAdvance();

        SJGTypeSetBoxUtil2.kindWs[extend_method]=[];
        SJGTypeSetBoxUtil2.kindHs[extend_method]=[];

        for(var i=0;i<SJGTypeSetBoxUtil2.MAX_BOX_NUM;i++) {
            advance.extend_method=extend_method;
            advance.limit=SJGTypeSetBoxUtil2.MAX_BOX_NUM;
            advance.count=i+1;
            advance.diagonal=SJGReplaceGroupAdvance.DIAGONAL_1;
            
            var ret: Array<ObjPositionAlign>=SJGTypeSetBoxUtil2.calcPosition(advance,groupW,groupH);
            if(ret&&ret.length>0) {
                SJGTypeSetBoxUtil2.kindWs[extend_method].push(ret[0].w);
                SJGTypeSetBoxUtil2.kindHs[extend_method].push(ret[0].h);
            }

        }
    }
    // 计算某种advance的子Box的个小数组
    // 参数：advance  
    // 参数：groupW  
    // 参数：groupH  
    public static calcPosition(advance: SJGReplaceGroupAdvance,
        groupW: number,groupH: number): Array<ObjPositionAlign> {
        var ret: Array<ObjPositionAlign>=null;
        // 文字组对象的宽高，保持不变，根据可替换数组的高级属性计算每个文字的位置
        switch(advance.extend_method) {
            case SJGReplaceGroup.HORIZON:
                ret=SJGTypeSetBoxUtil2.HORIZON(advance,groupW,groupH);
                break;
            case SJGReplaceGroup.VERTICLE:
                ret=SJGTypeSetBoxUtil2.VERTICLE(advance,groupW,groupH);
                break;
            case SJGReplaceGroup.CIRCLE:
                ret=SJGTypeSetBoxUtil2.CIRCLE(advance,groupW,groupH);
                break;
            case SJGReplaceGroup.RECT:
                ret=SJGTypeSetBoxUtil2.RECT(advance,groupW,groupH);
                break;
            case SJGReplaceGroup.W:
                ret=SJGTypeSetBoxUtil2.W(advance,groupW,groupH);
                break;
            case SJGReplaceGroup.PATH:
                ret=SJGTypeSetBoxUtil2.PATH(advance,groupW,groupH);
                break;

            default:

                break;
        }
        return ret;
    }
    
    
    // 组 －0横向扩展
    // 参数：p页面
    // 参数：group标题组
    // 参数：callback 为async的回调函数，例如：asyncCallback(null, 'one');
    public static HORIZON(advance: SJGReplaceGroupAdvance,
        groupW: number,groupH: number): Array<ObjPositionAlign> {
        var ret: Array<ObjPositionAlign>=new Array<ObjPositionAlign>();


        var col: number=advance.limit;
        var row: number=1;

        if(advance.count<=advance.limit) {
            col=advance.count;
            row=1;
        } else {
            col=advance.limit;
            row=Math.ceil(advance.count/advance.limit);
        }

        var x=0;
        var y=0;
        var w=groupW/col;
        var h=groupH/row;

        for(var i=0;i<row;i++) {
            for(var j=0;j<col;j++) {
                var pos: ObjPositionAlign=new ObjPositionAlign(x+w*j,y+h*i,w,h, 0,ObjPositionAlign.ALIGN_POINT_7);
                SJGTypeSetBoxUtil2.adjustStartPoint(advance,pos);
                ret.push(pos);

                // 最后一行特殊处理
                if(i==row-1) {
                    if(advance.tail_pos == SJGReplaceGroupAdvance.TAIL_POS_2){
                        var remain=row*col-advance.count;
                        var xOffset=remain/2*w;
                        pos.x+=xOffset;                        
                    } else if(advance.tail_pos==SJGReplaceGroupAdvance.TAIL_POS_3) {
                        var remain=row*col-advance.count;
                        var xOffset=remain*w;
                        pos.x+=xOffset;
                    }
                }

                if(ret.length>=advance.count) {
                    break;
                }
            }
            
        }

        return ret;
    }
        
    // 组 －1垂直扩展
    // 参数：p页面
    // 参数：group标题组
    // 参数：callback 为async的回调函数，例如：asyncCallback(null, 'one');
    public static VERTICLE(advance: SJGReplaceGroupAdvance,
        groupW: number,groupH: number): Array<ObjPositionAlign> {
        var ret: Array<ObjPositionAlign>=new Array<ObjPositionAlign>();

        var row: number=advance.limit;
        var col: number=1;

        if(advance.count<=advance.limit) {
            row=advance.count;
            col=1;
        } else {
            row=advance.limit;
            col=Math.ceil(advance.count/advance.limit);
        }

        var x=0;
        var y=0;
        var w=groupW/col;
        var h=groupH/row;

        for(var i=0;i<col;i++) {
            for(var j=0;j<row;j++) {
                var pos: ObjPositionAlign=new ObjPositionAlign(x+w*i,y+h*j,w,h,0,ObjPositionAlign.ALIGN_POINT_7);
                SJGTypeSetBoxUtil2.adjustStartPoint(advance,pos);
                ret.push(pos);
                
                // 最后一行特殊处理
                if(i==col-1) {
                    if(advance.tail_pos==SJGReplaceGroupAdvance.TAIL_POS_2) {
                        var remain=row*col-advance.count;
                        var yOffset=remain/2*h;
                        pos.y+=yOffset;
                    } else if(advance.tail_pos==SJGReplaceGroupAdvance.TAIL_POS_3) {
                        var remain=row*col-advance.count;
                        var yOffset=remain*h;
                        pos.y+=yOffset;
                    }
                }
                
                if(ret.length>=advance.count) {
                    break;
                }
            }
        }

        return ret;
    }
        
    // 组 －2圆形扩展
    // 参数：p页面
    // 参数：group标题组
    // 参数：callback 为async的回调函数，例如：asyncCallback(null, 'one');
    public static CIRCLE(advance: SJGReplaceGroupAdvance,
        groupW: number,groupH: number): Array<ObjPositionAlign> {
        var ret: Array<ObjPositionAlign>=new Array<ObjPositionAlign>();

        var len=advance.count;
        if(len>0) {
            if(len==1) {
                ret.push(new ObjPositionAlign(0,0,groupW,groupH,0,ObjPositionAlign.ALIGN_POINT_7));
            } else {
                // 计算宽高：
                var avg=Math.PI*2/len;
                var x=0;
                var y=0;
                //var w=groupW/len;
                //var h=groupH/len;
                
                // 宽度：保证第1、2个提示框靠在一起
                var w=(len==2)? (groupW/2):(groupW/2)*Math.sin(avg);
                // 高度: 尽量保证提示框靠在一起但不重叠
                var h=(groupH/2)*(Math.cos(avg)-Math.cos(2*avg));// 默认第2、3个靠在一起
                switch(len) {// 特殊处理
                    case 2: h=groupH; break;
                    case 3: h=(groupH/2)*(1-Math.cos(avg)); break;
                    case 7: h=(groupH/2)*(Math.cos(2*avg)-Math.cos(3*avg)); break;
                }
                
                // 计算外接矩形和对齐方式
                if(len==2) {
                    ret.push(new ObjPositionAlign(0,0,w,h,0,ObjPositionAlign.ALIGN_POINT_7));
                    ret.push(new ObjPositionAlign(groupW/2,0,w,h,0,ObjPositionAlign.ALIGN_POINT_7));
                } else if(len==3) {
                    var SIN1=Math.sin(Math.PI/180*60);
                    var COS1=Math.cos(Math.PI/180*60);
                    ret.push(new ObjPositionAlign(
                        groupW/2,
                        0,
                        w,
                        h,
                        0,
                        ObjPositionAlign.ALIGN_POINT_4));
                    ret.push(new ObjPositionAlign(
                        groupW/2*(1+SIN1),
                        groupH/2*(1+COS1),
                        w,
                        h,
                        0,
                        ObjPositionAlign.ALIGN_POINT_7));
                    ret.push(new ObjPositionAlign(
                        groupW/2*(1-SIN1),
                        groupH/2*(1+COS1),
                        w,
                        h,
                        0,
                        ObjPositionAlign.ALIGN_POINT_1));

                } else if(len==4) {
                    var SIN1=Math.sin(Math.PI/180*45);
                    var COS1=Math.cos(Math.PI/180*45);

                    ret.push(new ObjPositionAlign(
                        groupW/2*(1-SIN1),
                        groupH/2*(1-COS1),
                        w,
                        h,
                        0,
                        ObjPositionAlign.ALIGN_POINT_2));
                    ret.push(new ObjPositionAlign(
                        groupW/2*(1+SIN1),
                        groupH/2*(1-COS1),
                        w,
                        h,
                        0,
                        ObjPositionAlign.ALIGN_POINT_6));
                    ret.push(new ObjPositionAlign(
                        groupW/2*(1+SIN1),
                        groupH/2*(1+COS1),
                        w,
                        h,
                        0,
                        ObjPositionAlign.ALIGN_POINT_6));
                    ret.push(new ObjPositionAlign(
                        groupW/2*(1-SIN1),
                        groupH/2*(1+COS1),
                        w,
                        h,
                        0,
                        ObjPositionAlign.ALIGN_POINT_2));

                } else if(len==5) {
                    var SIN1=Math.sin(Math.PI/180*72);
                    var COS1=Math.cos(Math.PI/180*72);
                    var SIN2=Math.sin(Math.PI/180*36);
                    var COS2=Math.cos(Math.PI/180*36);
                    ret.push(new ObjPositionAlign(
                        groupW/2,
                        0,
                        w,
                        h,
                        0,
                        ObjPositionAlign.ALIGN_POINT_4));
                    ret.push(new ObjPositionAlign(
                        groupW/2*(1+SIN1),
                        groupH/2*(1-COS1),
                        w,
                        h,
                        0,
                        ObjPositionAlign.ALIGN_POINT_6));
                    ret.push(new ObjPositionAlign(
                        groupW/2*(1+SIN2),
                        groupH/2*(1+COS2),
                        w,
                        h,
                        0,
                        ObjPositionAlign.ALIGN_POINT_7));
                    ret.push(new ObjPositionAlign(
                        groupW/2*(1-SIN2),
                        groupH/2*(1+COS2),
                        w,
                        h,
                        0,
                        ObjPositionAlign.ALIGN_POINT_1));
                    ret.push(new ObjPositionAlign(
                        groupW/2*(1-SIN1),
                        groupH/2*(1-COS1),
                        w,
                        h,
                        0,
                        ObjPositionAlign.ALIGN_POINT_2));
                } else if(len==6) {
                    var SIN1=Math.sin(Math.PI/180*30);
                    var COS1=Math.cos(Math.PI/180*30);

                    ret.push(new ObjPositionAlign(
                        groupW/2*(1+SIN1),
                        groupH/2*(1-COS1),
                        w,
                        h,
                        0,
                        ObjPositionAlign.ALIGN_POINT_6));
                    ret.push(new ObjPositionAlign(
                        groupW,
                        groupH/2,
                        w,
                        h,
                        0,
                        ObjPositionAlign.ALIGN_POINT_6));
                    ret.push(new ObjPositionAlign(
                        groupW/2*(1+SIN1),
                        groupH/2*(1+COS1),
                        w,
                        h,
                        0,
                        ObjPositionAlign.ALIGN_POINT_6));
                    ret.push(new ObjPositionAlign(
                        groupW/2*(1-SIN1),
                        groupH/2*(1+COS1),
                        w,
                        h,
                        0,
                        ObjPositionAlign.ALIGN_POINT_2));
                    ret.push(new ObjPositionAlign(
                        0,
                        groupH/2,
                        w,
                        h,
                        0,
                        ObjPositionAlign.ALIGN_POINT_2));
                    ret.push(new ObjPositionAlign(
                        groupW/2*(1-SIN1),
                        groupH/2*(1-COS1),
                        w,
                        h,
                        0,
                        ObjPositionAlign.ALIGN_POINT_2));
                } else if(len==7) {
                    var SIN1=Math.sin(Math.PI/180*51);
                    var COS1=Math.cos(Math.PI/180*51);
                    var SIN2=Math.sin(Math.PI/180*12);
                    var COS2=Math.cos(Math.PI/180*12);
                    var SIN3=Math.sin(Math.PI/180*63);
                    var COS3=Math.cos(Math.PI/180*63);
                    ret.push(new ObjPositionAlign(
                        groupW/2,
                        0,
                        w,
                        h,
                        0,
                        ObjPositionAlign.ALIGN_POINT_4));
                    ret.push(new ObjPositionAlign(
                        groupW/2*(1+SIN1),
                        groupH/2*(1-COS1),
                        w,
                        h,
                        0,
                        ObjPositionAlign.ALIGN_POINT_6));
                    ret.push(new ObjPositionAlign(
                        groupW/2*(1+COS2),
                        groupH/2*(1+SIN2),
                        w,
                        h,
                        0,
                        ObjPositionAlign.ALIGN_POINT_6));
                    ret.push(new ObjPositionAlign(
                        groupW/2*(1+COS3),
                        groupH/2*(1+SIN3),
                        w,
                        h,
                        0,
                        ObjPositionAlign.ALIGN_POINT_7));
                    ret.push(new ObjPositionAlign(
                        groupW/2*(1-COS3),
                        groupH/2*(1+SIN3),
                        w,
                        h,
                        0,
                        ObjPositionAlign.ALIGN_POINT_1));
                    ret.push(new ObjPositionAlign(
                        groupW/2*(1-COS2),
                        groupH/2*(1+SIN2),
                        w,
                        h,
                        0,
                        ObjPositionAlign.ALIGN_POINT_2));
                    ret.push(new ObjPositionAlign(
                        groupW/2*(1-SIN1),
                        groupH/2*(1-COS1),
                        w,
                        h,
                        0,
                        ObjPositionAlign.ALIGN_POINT_2));

                } else if(len==8) {
                    var SIN1=Math.sin(Math.PI/180*22.5);
                    var COS1=Math.cos(Math.PI/180*22.5);
                    var SIN2=Math.sin(Math.PI/180*67.5);
                    var COS2=Math.cos(Math.PI/180*67.5);

                    ret.push(new ObjPositionAlign(
                        groupW/2*(1+SIN1),
                        groupH/2*(1-COS1),
                        w,
                        h,
                        0,
                        ObjPositionAlign.ALIGN_POINT_5));
                    ret.push(new ObjPositionAlign(
                        groupW/2*(1+SIN2),
                        groupH/2*(1-COS2),
                        w,
                        h,
                        0,
                        ObjPositionAlign.ALIGN_POINT_6));
                    ret.push(new ObjPositionAlign(
                        groupW/2*(1+SIN2),
                        groupH/2*(1+COS2),
                        w,
                        h,
                        0,
                        ObjPositionAlign.ALIGN_POINT_6));
                    ret.push(new ObjPositionAlign(
                        groupW/2*(1+SIN1),
                        groupH/2*(1+COS1),
                        w,
                        h,
                        0,
                        ObjPositionAlign.ALIGN_POINT_7));
                    ret.push(new ObjPositionAlign(
                        groupW/2*(1-SIN1),
                        groupH/2*(1+COS1),
                        w,
                        h,
                        0,
                        ObjPositionAlign.ALIGN_POINT_1));
                    ret.push(new ObjPositionAlign(
                        groupW/2*(1-SIN2),
                        groupH/2*(1+COS2),
                        w,
                        h,
                        0,
                        ObjPositionAlign.ALIGN_POINT_2));
                    ret.push(new ObjPositionAlign(
                        groupW/2*(1-SIN2),
                        groupH/2*(1-COS2),
                        w,
                        h,
                        0,
                        ObjPositionAlign.ALIGN_POINT_2));
                    ret.push(new ObjPositionAlign(
                        groupW/2*(1-SIN1),
                        groupH/2*(1-COS1),
                        w,
                        h,
                        0,
                        ObjPositionAlign.ALIGN_POINT_3));
                }
                
                
            } 
            
            
        }
        

        return ret;
    }
    // 组 －3矩形对角线扩展
    // 参数：p页面
    // 参数：group标题组
    // 参数：callback 为async的回调函数，例如：asyncCallback(null, 'one');
    public static RECT(advance: SJGReplaceGroupAdvance,
        groupW: number,groupH: number): Array<ObjPositionAlign> {
        
        if(advance.diagonal == SJGReplaceGroupAdvance.DIAGONAL_1){
            return SJGTypeSetBoxUtil2.RECT_LT_2_RB(advance,groupW,groupH);   
        } else if(advance.diagonal==SJGReplaceGroupAdvance.DIAGONAL_2) {
            return SJGTypeSetBoxUtil2.RECT_RT_2_LB(advance,groupW,groupH);
        } 
        return [];
    }
    // 组 －3矩形对角线扩展-左上到右下
    // 参数：p页面
    // 参数：group标题组
    // 参数：callback 为async的回调函数，例如：asyncCallback(null, 'one');
    public static RECT_LT_2_RB(advance: SJGReplaceGroupAdvance,
        groupW: number,groupH: number): Array<ObjPositionAlign> {
        var ret: Array<ObjPositionAlign>=new Array<ObjPositionAlign>();

        // 计算宽高
        var h: number=groupH/advance.count;
        var w: number=groupW;
        if(advance.count==2) {
            w=groupW/2;
        } else if(advance.count>=3) {
            w=groupW/3;
        }
        // 计算对齐点
        var a0=ObjPositionAlign.ALIGN_POINT_8; 
        var a1=ObjPositionAlign.ALIGN_POINT_8;
        if(advance.count>1){
            // 内部编组的位置： 1表示内部编组在对角线左侧 2表示右侧 3表示左右交错 4表示右左交错
            if(advance.diagonal_align==SJGReplaceGroupAdvance.DIAGONAL_ALIGN_1){
                a0=ObjPositionAlign.ALIGN_POINT_2;
                a1=ObjPositionAlign.ALIGN_POINT_2;
            } else if(advance.diagonal_align==SJGReplaceGroupAdvance.DIAGONAL_ALIGN_2) {
                a0=ObjPositionAlign.ALIGN_POINT_6;
                a1=ObjPositionAlign.ALIGN_POINT_6;
            } else if(advance.diagonal_align==SJGReplaceGroupAdvance.DIAGONAL_ALIGN_3) {
                a0=ObjPositionAlign.ALIGN_POINT_2;
                a1=ObjPositionAlign.ALIGN_POINT_6;
            } else if(advance.diagonal_align==SJGReplaceGroupAdvance.DIAGONAL_ALIGN_4) {
                a0=ObjPositionAlign.ALIGN_POINT_6;
                a1=ObjPositionAlign.ALIGN_POINT_2;
            }
        }
        // 计算位置
        for(var i=0;i<advance.count;i++){
            // 分奇偶处理
            var a=(i%2==0)? a0:a1;
            
            ret.push(new ObjPositionAlign(
                groupW*(i+1)/(advance.count+1),
                groupH*(i+1)/(advance.count+1),
                w,
                h,
                0,
                a));
        }
        
            
        return ret;
    }
    // 组 －3矩形对角线扩展-右上到左下
    // 参数：p页面
    // 参数：group标题组
    // 参数：callback 为async的回调函数，例如：asyncCallback(null, 'one');
    public static RECT_RT_2_LB(advance: SJGReplaceGroupAdvance,
        groupW: number,groupH: number): Array<ObjPositionAlign> {
        var ret: Array<ObjPositionAlign>=new Array<ObjPositionAlign>();

        // 计算宽高
        var h: number=groupH/advance.count;
        var w: number=groupW;
        if(advance.count==2) {
            w=groupW/2;
        } else if(advance.count>=3) {
            w=groupW/3;
        }
        // 计算对齐点
        var a0=ObjPositionAlign.ALIGN_POINT_8;
        var a1=ObjPositionAlign.ALIGN_POINT_8;
        if(advance.count>1) {
            // 内部编组的位置： 1表示内部编组在对角线左侧 2表示右侧 3表示左右交错 4表示右左交错
            if(advance.diagonal_align==SJGReplaceGroupAdvance.DIAGONAL_ALIGN_1) {
                a0=ObjPositionAlign.ALIGN_POINT_2;
                a1=ObjPositionAlign.ALIGN_POINT_2;
            } else if(advance.diagonal_align==SJGReplaceGroupAdvance.DIAGONAL_ALIGN_2) {
                a0=ObjPositionAlign.ALIGN_POINT_6;
                a1=ObjPositionAlign.ALIGN_POINT_6;
            } else if(advance.diagonal_align==SJGReplaceGroupAdvance.DIAGONAL_ALIGN_3) {
                a0=ObjPositionAlign.ALIGN_POINT_2;
                a1=ObjPositionAlign.ALIGN_POINT_6;
            } else if(advance.diagonal_align==SJGReplaceGroupAdvance.DIAGONAL_ALIGN_4) {
                a0=ObjPositionAlign.ALIGN_POINT_6;
                a1=ObjPositionAlign.ALIGN_POINT_2;
            }
        }
        // 计算位置
        for(var i=0;i<advance.count;i++) {
            // 分奇偶处理
            var a=(i%2==0)? a0:a1;

            ret.push(new ObjPositionAlign(
                groupW-groupW*(i+1)/(advance.count+1),
                groupH*(i+1)/(advance.count+1),
                w,
                h,
                0,
                a));
        }
        
            
            
        return ret;
    }
        
    // 组 －4W形扩展
    // 参数：p页面
    // 参数：group标题组
    // 参数：callback 为async的回调函数，例如：asyncCallback(null, 'one');
    public static W(advance: SJGReplaceGroupAdvance,
        groupW: number,groupH: number): Array<ObjPositionAlign> {
        var ret: Array<ObjPositionAlign>=new Array<ObjPositionAlign>();

        var len=advance.count;
        if(len>0) {
            if(len==1) {
                var pos: ObjPositionAlign=new ObjPositionAlign(0,0,groupW,groupH,0,ObjPositionAlign.ALIGN_POINT_7);
                SJGTypeSetBoxUtil2.adjustStartPoint(advance,pos);
                ret.push(pos);
            } else {

                var x=0;
                var y=0;
                var w=groupW/len;
                var h=groupH/2;//groupH/len;
                // w扩展
                for(var i=0;i<len;i++) {
                    // 上部分
                    var pos: ObjPositionAlign=null;
                    if(i%2==0) {
                        pos=new ObjPositionAlign(
                            x+i*w,
                            y,
                            w,h,0,ObjPositionAlign.ALIGN_POINT_7);
                    } else { 
                        // 下部分
                        pos=new ObjPositionAlign(
                            x+i*w,
                            y+groupH-h,//y+groupH,
                            w,h,0,ObjPositionAlign.ALIGN_POINT_7);
                    }
                    SJGTypeSetBoxUtil2.adjustStartPoint(advance,pos);
                    ret.push(pos);
                }
            }
        }
        return ret;
    }
        
    // 组 －5按路径扩展
    // 参数：p页面
    // 参数：group标题组
    // 参数：callback 为async的回调函数，例如：asyncCallback(null, 'one');
    public static PATH(advance: SJGReplaceGroupAdvance,
        groupW: number,groupH: number): Array<ObjPositionAlign> {
        var ret: Array<ObjPositionAlign>=new Array<ObjPositionAlign>();

        

        return ret;
    }
        
    // 根据对齐点，纠正起点
    // 参数：group
    // 参数：pos，默认为左上角
    public static adjustStartPoint(advance: SJGReplaceGroupAdvance,pos: ObjPositionAlign) {
        
    }
    
    

//SJG_MARK_APPEND--------------------

}//SJG_MARK_END-------------------------

